package cs340.stormtroopers.junitTests;

import cs340.stormtroopers.hypeerweb.Node;
import cs340.stormtroopers.hypeerweb.WebId;
import junit.framework.TestCase;

public class NodeTests extends TestCase
{
	public void testNodeGetters()
	{
		Node n0 = new Node(1);
		assertTrue(n0.getWebId().getValue() == 1);
		assertTrue(n0.getFold().getWebId().getValue() == 1);

		Node n1 = new Node(1, 2);

		assertTrue(n1.getWebId() != null);
		// There used to be a bug here. The constructor rejected a webid if it
		// was > 0. I fixed it :)

		assertTrue(n1.getWebId().getValue() == 1);
		assertTrue(n1.getWebId().getHeight() == 2);
	}

	public void testNodeNeighbors()
	{
		Node n0 = new Node(0);
		assertTrue(n0.getNeighbors().isEmpty());

		Node n1 = new Node(1);
		Node n2 = new Node(2);
		Node n3 = new Node(3);

		n0.addNeighbor(n1);
		n0.addNeighbor(n2);
		n0.addNeighbor(n3);

		assertFalse(n0.getNeighbors().isEmpty());
		assertTrue(n0.getNeighbors().size() == 3);

		n0.removeNeighbor(n1);
		n0.removeNeighbor(n2);
		n0.removeNeighbor(n3);

		assertTrue(n0.getNeighbors().isEmpty());
	}

	public void testNodeUpPointers()
	{
		Node n0 = new Node(0);
		assertTrue(n0.getUpPointers().isEmpty());

		Node n1 = new Node(1);
		Node n2 = new Node(2);
		Node n3 = new Node(3);

		n0.addUpPointer(n1);
		n0.addUpPointer(n2);
		n0.addUpPointer(n3);

		assertFalse(n0.getUpPointers().isEmpty());
		assertTrue(n0.getUpPointers().size() == 3);

		n0.removeUpPointer(n1);
		n0.removeUpPointer(n2);
		n0.removeUpPointer(n3);

		assertTrue(n0.getUpPointers().isEmpty());
	}

	public void testNodeDownPointers()
	{
		Node n0 = new Node(0);
		assertTrue(n0.getDownPointers().isEmpty());

		Node n1 = new Node(1);
		Node n2 = new Node(2);
		Node n3 = new Node(3);

		n0.addDownPointer(n1);
		n0.addDownPointer(n2);
		n0.addDownPointer(n3);

		assertFalse(n0.getDownPointers().isEmpty());
		assertTrue(n0.getDownPointers().size() == 3);

		n0.removeDownPointer(n1);
		n0.removeDownPointer(n2);
		n0.removeDownPointer(n3);

		assertTrue(n0.getDownPointers().isEmpty());
	}

	public void testNodeSetters()
	{
		Node n0 = new Node(0);
		assertTrue(n0.getFold().getWebId().getValue() == 0);
		assertTrue(n0.getSurrogateFold() == Node.NULL_NODE);
		assertTrue(n0.getInverseSurrogateFold() == Node.NULL_NODE);

		Node n1 = new Node(1);
		Node n2 = new Node(2);
		Node n3 = new Node(3);

		n0.setFold(n1);
		n0.setSurrogateFold(n2);
		n0.setInverseSurrogateFold(n3);

		assertTrue(n0.getFold().getWebId().getValue() == 1);
		assertTrue(n0.getSurrogateFold().getWebId().getValue() == 2);
		assertTrue(n0.getInverseSurrogateFold().getWebId().getValue() == 3);

		WebId w = new WebId(5);
		n0.setWebId(w);
		assertTrue(n0.getWebId().getValue() == 5);
	}
}
